package com.wellink.listviewsample.com.wellink.listviewsample.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wellink.listviewsample.R;

public class MyArrayAdapter extends ArrayAdapter {

    private Activity activity;
    private int resId;
    private String[] items;

    public MyArrayAdapter(Activity activity,int resId,String[] items){
        super(activity,resId,items);
        this.activity = activity;
        this.resId = resId;
        this.items = items;
    }


    @Override
    public @NonNull
    View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = activity.getLayoutInflater();
        View itemView = inflater.inflate(resId,null);

        TextView textView = itemView.findViewById(R.id.content_tv);
        ImageView imageView = itemView.findViewById(R.id.icon_img);

        String content = items[position].trim();

        textView.setText(content);
        if(content.startsWith("a") || content.startsWith("A")){
            imageView.setImageResource(R.drawable.letter1);
        }else if(content.startsWith("b") || content.startsWith("B")){
            imageView.setImageResource(R.drawable.letter2);
        }else if(content.startsWith("c")|| content.startsWith("C")){
            imageView.setImageResource(R.drawable.letter3);
        }else if(content.startsWith("d")|| content.startsWith("D")){
            imageView.setImageResource(R.drawable.letter4);
        }else{
            imageView.setImageResource(R.drawable.letter5);
        }

        return  itemView;
    }

}
